package cn.jolyoulu.common.swagger;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: JolyouLu
 * @Date: 2023/1/20 19:00
 * @Description
 */
@Configuration
//Profile是方法1（只在dev和test环境下开启）
@Profile({"dev", "test"})
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public OpenAPI springOpenAPI() {
        Contact contact = new Contact();
        contact.setName("xxxx");
        contact.setUrl("https://www.baidu.com/");
        contact.setEmail("xxx@qq.com");
        return new OpenAPI()
                .info(new Info()
                        .title("Swagger接口文档")
                        .description("如有疑问，请联系xxx@qq.com")
                        .version("0.0.1")
                        .contact(contact)
                        .version("1.0"));
    }

    /**
     * 配置分组，扫描指定路径
     * @return
     */
    @Bean
    public GroupedOpenApi publicApi() {
        return GroupedOpenApi.builder()
                .group("test-api")
                .pathsToMatch("/test/**")
                .build();
    }

}
